package band.wukong.practice.java.core.pack.util;

import java.io.*;
import java.util.Properties;
import java.util.ResourceBundle;

public class PropertiesSample {

    public static void way1() throws IOException {
        InputStream is = null;
        try {
            is = new FileInputStream(System.getProperty("user.dir") + "\\app.properties");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        Properties p = new Properties();
        try {
            p.load(is);
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }

        System.out.println(p.getProperty("copyright"));
    }

    public static void way2() throws IOException {
        BufferedReader reader;
        try {
            reader = new BufferedReader(new FileReader(
                    System.getProperty("user.dir") + "\\app.properties"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw e;
        }

        Properties p = new Properties();
        try {
            p.load(reader);
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }

        System.out.println(p.getProperty("copyright"));
    }

    public static void way3() {
        ResourceBundle rs =
                ResourceBundle.getBundle("app");

        System.out.println(rs.getString("copyright"));

    }

    /**
     * @param args
     * @param
     */
    public static void main(String[] args) {
        way3();
    }
}
